import React, {Component} from 'react';
import request from "../utils/request";
import {connect} from "dva";

class Detail extends Component {
  state = {
    filmDetail: ''
  }

  componentDidMount() {
    // 利用传过来的id值请求详情页面数据
    console.log(this.props.match.params.id)

    // 利用 connect 包装后通过属性可以得到 dispatch
    this.props.dispatch({
      type: "tabbarShow/hide"
    })

    request(`https://m.maizuo.com/gateway?filmId=${this.props.match.params.id}&k=7754252`, {
      headers: {
        'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.0","e":"1640782700594797135921153","bc":"440100"}',
        'X-Host': 'mall.film-ticket.film.info'
      }
    }).then(res => {
      console.log(res.data.data.film)
      this.setState({
        filmDetail: res.data.data.film
      })
    })
  }

  componentWillUnmount() {
    this.props.dispatch({
      type: "tabbarShow/show"
    })
  }

  render() {
    return (
      <div>
        <div>{this.state.filmDetail.name}</div>
        <img src={this.state.filmDetail.poster} alt="" style={{width: '100%'}}/>
      </div>
    );
  }
}

export default connect()(Detail)
